package nbcp.db.mongo.entity

import nbcp.base.comm.ProductRef
import nbcp.base.comm.WxUserInfoRef
import nbcp.db.*
import org.springframework.data.mongodb.core.mapping.Document
import nbcp.db.mongo.MongoEntityGroup
import nbcp.db.mongo.*
import java.time.LocalDate
import java.time.LocalDateTime

/**
 * Created by yuxh on 2018/11/5
 */

@Document
@MongoEntityGroup("shop")
data class HomeData(
        var corpId: String = "",
        var hot1: ProductCard = ProductCard(),
        var hot2: ProductCard = ProductCard(),
        var hot3: ProductCard = ProductCard(),
        var hot4: ProductCard = ProductCard(),
        var hot5: ProductCard = ProductCard(),
        var new1: ProductCard = ProductCard(),
        var new2: ProductCard = ProductCard(),
        var new3: ProductCard = ProductCard(),
        var recent1: ProductCard = ProductCard(),
        var recent2: ProductCard = ProductCard(),
        var recent3: ProductCard = ProductCard(),
        var recent4: ProductCard = ProductCard()
) : IMongoDocument()

@Document
@MongoEntityGroup("shop")
data class ShopUser(
        var level: OpenUserLevelEnum = OpenUserLevelEnum.Start0,
        var logo: String = "",     //远程URL
        var password: String = "", //小程序不需要，手机App需要。
        var invoices: MutableList<InvoiceData> = mutableListOf(InvoiceData(default = true)),
        var receiveAddresses: MutableList<SysCorporation_ReceiveAddress> = mutableListOf(),
        var createAt: LocalDateTime = LocalDateTime.now(),
        var loginName: String = "",

        var idCardNumber: String = "",
        var email: String = "",
        var mobile: String = "",
        var qq: String = "",
        var birthday: LocalDate?,
        var wxOpenId: String = "",
        var sex: UserSexEnum,
        open var name: String = ""
) : IMongoDocument() {

    fun toWxUserInfo(): WxUserInfoRef {
        var ret = WxUserInfoRef();
        ret.id = this.id;
        ret.logo = this.logo;
        ret.name = this.name;
        ret.openId = this.wxOpenId;
        return ret;
    }
}

//分类
@Document
@MongoEntityGroup("shop")
data class SysCategory(
        var code: String = "", //树型结构。类似城市代码。
        var name: String = "",
        var english: String = "", //英文
        var pcode: String = "",
        var logo: IdUrl = IdUrl(),   //logo
        var order: Float = 0.0F,    //排序
        var corpId: String = "",    //企业Id
        var banner: IdUrl = IdUrl() //淘对Banner
) : IMongoDocument()


//@Document
//@MongoEntityGroup("shop")
//data class HomeData(
//        var hotProducts: MutableList<IdNameUrl> = mutableListOf(),
//        var products: MutableList<ProductRef> = mutableListOf()
//) : IMongoDocument()
/**
 * 优惠券
 */
@Document
@MongoEntityGroup("shop")
data class SysCoupon(
        var startAt: LocalDateTime?,
        var endAt: LocalDateTime?
) : IMongoDocument()

@Document
@MongoEntityGroup("shop")
data class WxFormId(
        var openId: String = "",
        var createAt: LocalDateTime = LocalDateTime.now(),
        var formId: String = "",
        var prePayId: String = "",  //prePayId 会有三条记录
        var used: Boolean = false,
        var usedAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()


//二维码购物车
@Document
@MongoEntityGroup("shop")
data class ShoppingCart(
        var product: IdName = IdName(), //绑定的商品
        var number: Int = 0, //数量
        var price: Int = 0, //单价
        var checked: Boolean = false, //是否选中
        var createBy: IdName = IdName(),
        var createAt: LocalDateTime = LocalDateTime.now(),
        var corp: IdName = IdName()
) : IMongoDocument()

@Document
@MongoEntityGroup("shop")
data class ArticleGroup(
        var group: String = "",
        var module: ArticleModuleEnum = ArticleModuleEnum.About, //所属模块,大类
        var order: Float = 0F,
        var corpId: String = "",
        var createAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()

@Document
@MongoEntityGroup("shop")
data class Article(
        var title: String = "",
        var authoer: String = "",
        var logo: IdUrl = IdUrl(), // 封面图
        var source: String = "",
        var body: String = "",
        var name: String = "", //唯一名称
        var group: String = "", //组，小类
        var module: ArticleModuleEnum = ArticleModuleEnum.About, //所属模块,大类
        var corpId: String = "",
        var order: Float = 0F,
        var createAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()